﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>会员专享服务</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<script type="text/javascript" src="../js/memberLevelSelecterNew.js"></script>
<script type="text/javascript" src="../js/memberServiceTypeSelecterNew.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
var _pagination = null;
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
});

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#actlrgTable").empty();
	var levelId = $("#searchLevelId").val();
	var typeId = $("#searchTypeId").val();
	var status = $("#searchStatus").val();
	var shopId = "";
	if($("#shopIsChoosed").is(":checked")){	
		shopId=$("#shopName").val();
		if(IsEmpty(shopId)){
			shopId = "";
		}
	}
	if(IsEmpty(levelId)){
		levelId = "";
	}
	if(IsEmpty(typeId)){
		typeId = "";
	}
	
	_pagination = new Pagination({
		url : '../memberOwnService/find/memberOwnServiceList/',
		data : {
			name : name,
			levelId : levelId,
			typeId : typeId,
			status : status,
			shopId : shopId
		},
		success : printDataToPage,
		pageSize : 10
	});
}

/**
 * 删除一行
 */
function toDelete(id,row) {
	if (IsEmpty(id)) {
		artError('未获取到主要信息！');
		return false;
	}
	
	//直接发出请求
	artConfirm("确认删除吗？", function() {
		qmsk.post("../memberOwnService/del",{'id' : id}, function(rst) {
			artSuccess("删除成功！");
			toSearch();
		});
	});
}


function printDataToPage(message){
	var oldBillNo = null;
	dataTable({
		tbodyId : 'actlrgTable',
		heads : ["ShopName", "LevelName","name","typeName","nums","memo","staName", ["id"]],
		rst : message,
		handler : [{
			col : 7,
			f : detail
		}],
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel() {
	$("#window_change,#yinying1").hide();
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel1() {
	$("#window_change1,#yinying1").hide();
}



function toAdd(){
	
	var shopHtml = $("#shopName").html();
	$("#shopId").html(shopHtml)
	restForm()

	$("#doflag").val(1)
	$("#window_change,#yinying1").show();
	addMargin($("#window_change"));
}

function toEdit(id){
	restForm()

	$("#doflag").val(2)
	$("#updateId").val(id)
	var dt = _findInfo("../memberOwnService/find/memberOwnServiceList/0/1", {'id':id})
	if(IsNotEmpty(dt)&&dt.state==0){
		var shopid = _getStringOfJson(0, dt, "shopid");
		var ShopName = _getStringOfJson(0, dt, "ShopName");
		var LevelName = _getStringOfJson(0, dt, "LevelName");
		var name = _getStringOfJson(0, dt, "name");
		var levelId = _getStringOfJson(0, dt, "levelId");
		var typeId = _getStringOfJson(0, dt, "typeId");
		var htm1 = "<option value="+shopid+">"+ShopName+"</option>"
		var htm2 = "<option value="+levelId+">"+LevelName+"</option>"
		var htm3 = "<option value="+typeId+">"+name+"</option>"
		$("#shopId").html(htm1)
		$("#memberId").html(htm2)
		$("#typeId").html(htm3)
		$("#content").val(_getStringOfJson(0, dt, "memo"))
		$("#status").val(_getStringOfJson(0, dt, "status"))

	}
	$("#window_change,#yinying1").show();
	addMargin($("#window_change"));
	
}

function edit(){
	var id = $("#updateId").val();
	var shopId = $("#shopId").val();
	var memberId = $("#memberId").val();
	var nums = $("#nums").val();
	var typeId = $("#typeId").val();
	var content = $("#content").val();
	var status = $("#status").val()
	var memo = $("#content").val()
	
	if(!checkNull(shopId, "店铺",null)||!checkNull(memberId, "会员级别", null)||!checkNull(typeId, "服务项目", null)){
		return false;
	}
	var heads = new Array("leveId","serviceTypeId","nums","memo","shopId","status","id");
	var datas = new Array(memberId,typeId,nums,memo,shopId,status,id);
	var jsonParserStr = _getJsonParseEditStr(heads, datas);
	qmsk.post("../memberOwnService/edit", {
		data : jsonParserStr
	}, function() {
		artSuccess("修改成功！");
		hideAddPanel();
		if (_pagination) {
			_pagination.reload();
		}
	});
}

function add() {
	var shopId = $("#shopId").val();
	var memberId = $("#memberId").val();
	var nums = $("#nums").val();
	var typeId = $("#typeId").val();
	var content = $("#content").val();
	var status = $("#status").val()
	var memo = $("#content").val()
	
	if(!checkNull(shopId, "店铺",null)||!checkNull(memberId, "会员级别", null)||!checkNull(typeId, "服务项目", null)){
		return false;
	}
	var heads = new Array("leveId","serviceTypeId","nums","memo","shopId","status");
	var datas = new Array(memberId,typeId,nums,memo,shopId,status);
	
	var jsonParserStr = _getJsonParseInsertStr(heads, datas);
	qmsk.post("../memberOwnService/insert", {
		data : jsonParserStr
	}, function() {
		artSuccess("添加成功！");
		restForm()
		hideAddPanel();
		toSearch();
	});
}

function detail(heads, row){
	return	"<input class='del common_btn' type='button' value='删除' onclick='toDelete("+heads+","+row+")'>"+"<input class='edit common_btn' type='button' value='修改' onclick='toEdit("+heads+")'>";
}

function save(){
	var doflag = $("#doflag").val();
	if(doflag==1){
		add();
	}else{
		edit();
	}
}

function restForm(){
	$("#shopId").val("")
	$("#memberId").html("")
	$("#typeId").html("")
	$("#nums").val("")
	$("#content").val("")
}


function openMemberLevel(){
	var shopId = $("#shopName").val();
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;

	}
	openMemberLevelListPanel("searchLevelId",shopId)
}

function openServiceType(){
	var shopId = $("#shopName").val();
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;

	}
	openMemberServiceTypeListPanel("searchTypeId",shopId)
}

function openMemberLevel2(){
	var shopId = $("#shopId").val();
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;

	}
	openMemberLevelListPanel("memberId",shopId)
}

function openServiceType2(){
	var shopId = $("#shopId").val();
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;

	}
	openMemberServiceTypeListPanel("typeId",shopId)
}
</script>
</head>

<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>
		<!-- 添加记录 弹出层 -->
		<div id="window_change" class="member_search hideDiv">
			<div class="closeTop">
			
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<input type="hidden" id="doflag">
			<input type="hidden" id="updateId">
			<p>
				<label ><span>店铺名称：</span>
					<select id="shopId" onclick="openShopListPanel(this)" >
       				 </select>
				</label>
				<label><span>会员级别：</span>
					<select id="memberId" onclick="openMemberLevel2()" >
       				 </select>
				</label>
			</p>
			<p>
				<label ><span>服务项目：</span>
					<select id="typeId" onclick="openServiceType2()" >
       				 </select>
				</label>
				<label ><span>次数：</span>
					<input type="text" id="nums" class="absoluteTxt">
				</label>
			</p>
			<p>
				<label ><span>状态：</span>
					<select id="status">
					<option value="0">使用</option>
					<option value="1">停用</option>
					</select>
				</label>
				<!-- <label ><span>成本：</span>
					<input type="text" id="cost" class="absoluteTxt">
					<input type="hidden" id="lgId">
				</label> -->
			</p>
			<p>
				<label style="didsplay:block;width:100%;"><span>描述：</span>
					
					<textarea id="content" style="width:400px;"></textarea>
				</label>
				
			</p>

			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="saveButton" onclick="save()">
			</div>
		</div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">会员专享服务</div>
    <div class="member_search">
     <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">店面：</span>
        <select id="shopName" onclick="openShopListPanel(this)" disabled="disabled">
        </select>
        <span>会员级别：</span>
        <select id="searchLevelId" onclick="openMemberLevel()" >
        </select>
        <span>服务类型：</span>
  		<select id="searchTypeId" onclick="openServiceType()" >
        </select>		<p>
		    
         <span>状态：</span>
        <select id="searchStatus"  >
        	<option value="">全部</option>
        	<option value="0">使用</option>
        	<option value="1">停用</option>
        </select>
        		<input class="btn" id="research" name="查询" type="button" value="查询" onClick="toSearch()" >
        
		</p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>会员专享服务列表 <span id="sup">共0条</span></strong><input
						type="button" class="common_btn" value="新增" id="addColumn" onclick="toAdd()">
      </caption>
      <thead>
        <tr>
          <th>店面</th>
          <th>会员级别</th>
          <th>服务项目</th>
          <th>服务类型</th>
          <th>服务次数</th>
          <th>备注</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="actlrgTable">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
